package com.jsd2412.backend.visitor.service.impl;

import com.jsd2412.backend.visitor.mapper.VisitorMapper;
import com.jsd2412.backend.visitor.pojo.dto.VisitorQuery;
import com.jsd2412.backend.visitor.pojo.dto.VisitorSaveParam;
import com.jsd2412.backend.visitor.pojo.entity.Visitor;
import com.jsd2412.backend.visitor.pojo.vo.VisitorVO;
import com.jsd2412.backend.visitor.service.VisitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class VisitorServiceImpl implements VisitorService {
    @Autowired
    private VisitorMapper visitorMapper;

//    @Autowired
//    private PatientMapper patientMapper;

    @Override
    public void saveVisitor(VisitorSaveParam visitorSaveParam) {
        log.debug("保存来访记录业务:参数={}", visitorSaveParam);
        Visitor visitor = new Visitor();
        BeanUtils.copyProperties(visitorSaveParam, visitor);
        if (visitorSaveParam.getId() == null) {//新增
            visitor.setCreateTime(new Date());
            visitorMapper.insert(visitor);
        } else {//更新
            visitorMapper.update(visitor);
        }
    }

    @Override
    public void deleteVisitor(Long id) {
        log.debug("删除来访记录业务:参数={}", id);
        visitorMapper.deleteById(id);
    }

    @Override
    public List<VisitorVO> selectVisitor(VisitorQuery visitorQuery) {
        log.debug("查询来访记录业务:参数={}", visitorQuery);

        //为查询参数对象补充受访老人姓名属性的值
        //PatientVO patientVO = patientMapper.selectById(visitorQuery.getPatientId());
        //visitorQuery.setName(patientVO.getName());

        return visitorMapper.select(visitorQuery);
    }
}
